home *** CD-ROM | disk | FTP | other *** search
/ KeyGen Studio 2002 / KeyGen_Studio_2002.iso / Tutorials / Eternal bliss / DEBUG3.ZIP / vbcrackme3.txt < prev    next >
Encoding:
Text File  |  1999-04-24  |  14.9 KB  |  399 lines

  1.             VBCrackMe 3 explained
  2.  
  3. Written by Etenal Bliss
  4. Email: Eternal_Bliss@hotmail.com
  5. Website: http://crackmes.cjb.net
  6.          http://surf.to/crackmes
  7. Date written: 23rd April 1999
  8.  
  9. Program Details:
  10. Language: Visual Basic
  11.  
  12. Learning Method:
  13. Code Explanation
  14. Parts of Softice Codes
  15.  
  16. Viewing Method:
  17. Use Notepad with Word Wrap switched OFF
  18. Screen Area set to 800 X 600 pixels (Optional)
  19.  
  20. __________________________________________________________________________
  21.  
  22.                 About the Essay
  23.  
  24. This is the third of the series of explanation on how coding in VB will
  25. affect the cracking process. In these essays, I'll also show you how crackmes
  26. are generally written in VB. I've included my thought processes that went
  27. through my mind while coding for this crackme.
  28.  
  29. If you have missed the first 2 essays, go to my website and get it. 
  30. Read it first before reading this because there are some parts 
  31. which I will not repeat here again.
  32.  
  33. I've added some of Rhytm's tutorial to make things clearer.
  34.  
  35. To fully understand what I am describing, it would help if you have the 
  36. CrackMe running and testing certain stuff out while you read.
  37.  
  38. __________________________________________________________________________
  39.  
  40.                 About the Protection
  41.  
  42. This crackme uses a hard-coded code which is hidden using another method
  43. different from the 1st CrackMe.
  44.  
  45. This is what I wrote in the textfile for this CrackMe:
  46. "Find the correct hardcoded code in this CrackMe. 
  47.  
  48. What you won't see:
  49. 1) The correct code using Hexeditor
  50. 2) The correct code in Softice
  51. 3) The correct code in SmartCheck"
  52.  
  53. In this CrackMe, instead of using String Compare (VBCrackMe 1) or Variant
  54. Compare (VBCrackMe 2), I used a variable that contains the data in Long
  55. format. This effectively makes cracking VB programs more difficult because
  56. there is no definite breakpoints like the previous 2 compare methods. The
  57. compare routine is in the main code itself and not in the DLL.
  58.  
  59. Instead of hiding the code, I used the manipulation of their Ascii to make
  60. sure that only 1 code will fit the 3 checks I created, thus only 1 code will
  61. be accepted. There was a bug in the CrackMe due to my error in calculations 
  62. and I'll explain it later. Because of this bug, a number of codes were
  63. accepted instead. 8(
  64.  
  65. __________________________________________________________________________
  66.  
  67.         A brief explanation on how VB coding is done...
  68.  
  69. Other than the things I mentioned in the first 2 essays, I'd like to add some
  70. more commands that are frequently used.
  71.  
  72. Len("word") - To get the length of the string, in this case, 4 chars
  73. **In SmartCheck, you will see Len(String:"word") returns LONG:4
  74.  
  75. __________________________________________________________________________
  76.  
  77.  
  78.                 Main Code
  79.  
  80. I've copied and pasted the main routine found in this crackme which is
  81. the protection scheme, the heart of the crackme. In the next section, I'll
  82. go into the explanation of some of the lines.
  83.  
  84. I've altered the name of the variables a bit so that they make sense. 8P
  85.  
  86.  
  87. Private Sub Command1_Click()
  88. Dim TotalNumber As Long, TrueTotal As Long
  89. Dim DivideNumber As Long, NumberToDivide As Long
  90. Dim r1 As Long, e As Long, v As Long, r As Long, s As Long
  91. On Error GoTo err1
  92.  
  93. DivideNumber = 11496889
  94. NumberToDivide = 2147483647
  95. r1 = 82
  96. e = 101
  97. v = 118
  98. r = 114
  99. s = 115
  100.  
  101. For z = 1 To Len(Text1.Text)
  102. TotalNumber = TotalNumber + Asc(Mid(Text1.Text, z, 1))
  103. Next z
  104.  
  105. TrueNumber = r1 + e + v + e + r + s + e
  106. If TotalNumber = TrueNumber Then
  107.  
  108. If ((Asc(Mid(Text1.Text, 2, 1)) = e) And (Asc(Mid(Text1.Text, 4, 1)) = e) And (Asc(Mid(Text1.Text, 7, 1)) = e)) Then
  109.  
  110. NumberToDivide = (NumberToDivide \ s) * r1) \ r) * e) \ v)
  111. If NumberToDivide = DivideNumber Then
  112.  
  113. Text1.Text = "You have cracked it!!"
  114. Text1.Enabled = False
  115. Command1.Visible = False
  116. Command3.Visible = True
  117. Command3.Enabled = True
  118. Command3.Caption = "&Again!"
  119. Command2.SetFocus
  120. GoTo err
  121.  
  122. Else
  123. GoTo err1
  124. End If
  125.  
  126. Else
  127. GoTo err1
  128. End If
  129.  
  130. Else
  131. err1:
  132. Text1.Text = "Wrong! Try Again!!"
  133. Text1.Enabled = False
  134. Command1.Visible = False
  135. Command3.Visible = True
  136. Command3.Enabled = True
  137. Command3.SetFocus
  138. End If
  139. err:
  140. End Sub
  141.  
  142.  
  143. __________________________________________________________________________
  144.  
  145.  
  146.                 Code Explanation
  147.  
  148. 1) Dim TotalNumber As Long, TrueTotal As Long
  149.    Dim DivideNumber As Long, NumberToDivide As Long
  150.    Dim r1 As Long, e As Long, v As Long, r As Long, s As Long
  151. ==========================================================================
  152. Like my 2nd CrackMe, I define what the variables will contain using the "Dim"
  153. command. You will notice that I've made all the variables to contain only
  154. Data type of Long. The usefulness of this will be shown later.
  155.  
  156.  
  157. 2) DivideNumber = 11496889
  158.    NumberToDivide = 2147483647
  159.    r1 = 82
  160.    e = 101
  161.    v = 118
  162.    r = 114
  163.    s = 115
  164. ==========================================================================
  165. These few lines are to tell the variables what their values are. If you see
  166. step 1, you will notice that all these values will be of the Long Data Type.
  167. One thing I found out was that by defining the values as Long, you will
  168. not see these numbers if you open up the CrackMe using a HexEditor.
  169. Therefore, it is another way of hiding numbers. But because Long Data Type
  170. can only contain numbers, it is kind of limited by the fact that other chars
  171. can not be hidden in this way.
  172.  
  173. Variables r1, e, v, r, s are the ascii values the code. As for DivideNumber
  174. and NumberToDivide, that's where the bug started. 8(
  175.  
  176.  
  177. 3) For z = 1 To Len(Text1.Text)
  178.    TotalNumber = TotalNumber + Asc(Mid(Text1.Text, z, 1))
  179.    Next z
  180. ==========================================================================
  181. This is the classical For...Next statement with some functions in it.
  182. "For z = 1 To Len(Text1.Text)" will tell the CrackMe to make a loop of n
  183. times where n is the length of the code you type in the textbox.
  184. (Therefore, "Len(Text1.Text)")
  185.  
  186. "TotalNumber = TotalNumber + Asc(Mid(Text1.Text, z, 1))" is to add
  187. up the Ascii value of individual characters found in the code you typed.
  188. Remeber the function of "Mid" and "Asc"? Here, "Mid" will be performed first
  189. to get the char and then "Asc" will convert it to its Ascii value.
  190.  
  191. "Next z" will tell the CrackMe to increase the value in z until it is equal
  192. to the length of the code you typed.
  193.  
  194.  
  195. 4) TrueNumber = r1 + e + v + e + r + s + e
  196. ==========================================================================
  197. This line tells the CrackMe to add up all the values of the variables I
  198. defined earlier. If you noticed, the code is "Reverse". 8P
  199.  
  200.  
  201. 5) If TotalNumber = TrueNumber Then
  202. ==========================================================================
  203. This is where the check occurs (the classical If...Then)
  204. "TotalNumber" is the variable containing the sum of the ascii values of the
  205. code you typed while "TrueNumber" is the correct ascii value.
  206. Looking at this, you will notice that there will be a lot of possible values
  207. for this CrackMe. Therefore, I coded for 2 more checks to make sure that only
  208. 1 code is accepted.
  209.  
  210. This is what Rhytm wrote in his tutorial:
  211. :00402DC9 8945C8          mov dword ptr [ebp-38], eax
  212. :00402DCC 8B45C0          mov eax, dword ptr [ebp-40]
  213. :00402DCF 3B45C8          cmp eax, dword ptr [ebp-38]
  214. :00402DD2 0F85B9060000    jne 00403491            <-- Important Compare
  215.  
  216. -----------------------------------------------------------------------------
  217.  
  218. Well just look at the values behind ebp-xx, add them together (Total: 2DC).
  219. You'll notice that the characters form the word "Reverse"
  220. This value is compared with the total of the the ascii values of your serial..
  221. Enter the serial and you've reversed this program !!!!
  222. Now I tried to enter a code containing my nickname and some other characters 
  223. that form a total of 2DC. And it didn't work :((
  224. So there is more work to do for us :)
  225.  
  226.  
  227.  
  228. 6) If ((Asc(Mid(Text1.Text, 2, 1)) = e) And (Asc(Mid(Text1.Text, 4, 1)) = e) 
  229.    And (Asc(Mid(Text1.Text, 7, 1)) = e)) Then
  230. ==========================================================================
  231. This is the second check. Again, the functions of "Asc" and "Mid" come into
  232. use. This line will check the 2nd, 4th and 7th char of the code you entered
  233. to make sure that they have the same value as the variable "e" which is 101 
  234. and that is the ascii value of the char "e". Remember that the code is 
  235. "Reverse".
  236.  
  237. This is what Rhytm wrote in his tutorial:
  238. Open smartcheck, load the program enter the correct code and take a look 
  239. at the new information:
  240.  
  241. MID(Variant:String:"Reverse",long:2,Variant:Integer:1)
  242. MID(Variant:String:"Reverse",long:4,Variant:Integer:1)
  243. MID(Variant:String:"Reverse",long:7,Variant:Integer:1)
  244.  
  245. Thus we see that the program checks is the characters at position 2, 4 and 7 
  246. are the same as the ones in the word reverse. 
  247. Knowing this we can find ourselves some other good serials.
  248. Examples:
  249. Reserve,Veserre,Peveste etc..
  250. You could have done this at the SoftICE way too, two of the checks would 
  251. be at addresses: 403115 and 403147  
  252.  
  253. End quote....
  254.  
  255. Well, the bug has shown...
  256.  
  257. 7) NumberToDivide = (NumberToDivide \ s) * r1) \ r) * e) \ v)
  258. If NumberToDivide = DivideNumber Then
  259. ==========================================================================
  260. This is where the bug is. I have defined the variables "NumberToDivide" and
  261. "DivideNumber" so that following the math routine of 
  262. "(NumberToDivide \ s) * r1) \ r) * e) \ v)", "NumberToDivide" will be a 
  263. specific value obtainable if the code is "Reverse". But due to error in my
  264. coding, I used the values of "s", "r1", "r", "e" and "v" for the routine which
  265. leads to the following "If...Then" statement will always be true. 
  266. Thus, only 2 checks are effective. This 3rd check is rendered useless.
  267.  
  268. What I intended to do was to use the ascii values of the 1st, 2nd, 3rd, 5th
  269. and 6th char of the code you typed to perform the math routine. Instead,
  270. I used the variables I defined.
  271.  
  272.  
  273. 8) Text1.Text = "You have cracked it!!"
  274.    Text1.Enabled = False
  275.    Command1.Visible = False
  276.    Command3.Visible = True
  277.    Command3.Enabled = True
  278.    Command3.Caption = "&Again!"
  279.    Command2.SetFocus
  280.    GoTo err
  281. ==========================================================================
  282. This whole chunk of codes is to show in the textbox "You have cracked it!!"
  283. when you entered the correct code and go to the end of the routine.
  284.  
  285.  
  286. 9) Else
  287.    GoTo err1
  288.    End If
  289.    Else
  290.    GoTo err1
  291.    End If
  292. ==========================================================================
  293. Notice 2 similar blocks of codes? The "Else...End If" is used twice here
  294. for these two "If...Then" statements.
  295. i) "If ((Asc(Mid(Text1.Text, 2, 1)) = e) And (Asc(Mid(Text1.Text, 4, 1)) = e) 
  296.    And (Asc(Mid(Text1.Text, 7, 1)) = e)) Then"
  297. ii)"If NumberToDivide = DivideNumber Then"
  298.  
  299. The "Else" here means that if the "If...Then" statement is not correct,
  300. it will perform the function within it, thus "GoTo err1".
  301. "Goto err1" tells the CrackMe to go to the location where there is a "pointer"
  302. named as "err1:" and will show the "Wrong! Try Again!!" message in the textbox.
  303.  
  304.  
  305. 10) Else
  306.     err1:
  307.     Text1.Text = "Wrong! Try Again!!"
  308.     Text1.Enabled = False
  309.     Command1.Visible = False
  310.     Command3.Visible = True
  311.     Command3.Enabled = True
  312.     Command3.SetFocus
  313.     End If
  314. ==========================================================================
  315. This is the final "Else" statement for the first "If...Then" statement which
  316. is "If TotalNumber = TrueNumber Then"
  317.  
  318. That is how VB works. If there are a few "If...Then" statements, the "End If"
  319. will be given to the closest "If...Then" statement unless it already have one.
  320. Eg.
  321. If...Then -----------------
  322.      If...Then ---------   |
  323.           If...Then -   |  |
  324.                      |  |  |
  325.           End If    -   |  |
  326.      End If ------------   | 
  327. End If --------------------
  328.  
  329.  
  330. "err1:" is a "pointer" for the CrackMe. In each of the "If...Then" statements,
  331. if the code entered is incorrect, the CrackMe will go to this part when the
  332. command "GoTo err1" is given.
  333.  
  334. __________________________________________________________________________
  335.  
  336.         How to Crack such VB protection schemes
  337.  
  338. In this 3rd CrackMe, there is no use of the String or Variant Compare and thus
  339. no compare breakpoints can be utilised. When Rhytm cracked the first check,
  340. he showed the codes seen in Softice and these codes are in the main program
  341. and not in the DLL file. Thus, there is no breakpoints like __vbaStrComp
  342. nor __vbaVarTstEq.
  343.  
  344. To break such a routine, SmartCheck is quite valuable because it shows a lot
  345. of information without you having to trace through all the junk codes VB
  346. uses. But, in SC, you will never see the compare done at all.
  347.  
  348. Softice is superior in this sense. Like what Rhytm did, he is able to
  349. see the compare in Softice. I quote again:
  350.  
  351. :00402DCC 8B45C0          mov eax, dword ptr [ebp-40]
  352. :00402DCF 3B45C8          cmp eax, dword ptr [ebp-38] <-- Important Compare
  353. :00402DD2 0F85B9060000    jne 00403491              <-- Jump if not Equal
  354.  
  355. See that? Just two lines will determine the fate of the code you entered.
  356. This is something like a cracker's nightmare. If all shareware authors uses
  357. other Data Types instead of "String" and "Variant", it would be quite hellish
  358. to crack VB programs. Firstly, Smartcheck will not be as useful and there will
  359. be no fixed breakpoints to use. Let's hope not a lot of them read this essay. 8P
  360.  
  361. One possible breakpoint I can think of if a shareware author uses 
  362. Long Data type is __vbai4str
  363. "__vbaI4Str" changes the value type from "String" to "Long". So, it might
  364. be worth trying out if "__vbaStrComp" and "__vbaVarTstEq" don't work.
  365.  
  366. __________________________________________________________________________
  367.  
  368.             Additional points
  369.  
  370.  
  371. For other breakpoints and compare methods, you can get my two essays on VB
  372. cracking found on my website.
  373.  
  374. SmartCheck logfile with the source is included together with this textfile
  375. "Debug3.zip". Unzip everything in it and double click on the debug3.sce file. 
  376.  
  377. If you have installed SmartCheck, SmartCheck will open up and the usual
  378. lot of information is shown. However, in this case, since the source code is
  379. included, when you click on threads in Command1_Click line, you will see
  380. how the source code is processed and how it is presented in SmartCheck.
  381. A definite learning experience for those who are struggling with SmartCheck usage.
  382. The first Command1_Click shows the lines processed when the correct code is
  383. entered. The second Command1_Click shows the lines processed when the code
  384. entered is wrong.
  385.  
  386. __________________________________________________________________________
  387.  
  388.                 End of File
  389.  
  390. I would like to thank Jeff for giving me this idea of writing essays on how
  391. I created my CrackMe, what commands will result in what breakpoints to use
  392. in Softice and how SmartCheck's usefulness is exploited.
  393.  
  394. Thanks to Rhytm for cracking my CrackMe as well. 8)
  395.  
  396. All the best to those reading this essay in VB cracking!
  397.  
  398.  
  399.